package pikes.ecma;

import pikes.core.Printable;
import pikes.core.PrintableCharSequence;

public class StringLiteral extends PrintableExpression implements IPrimaryExpression {

	private Printable string = null;

	public StringLiteral(CharSequence string) {
		this(new PrintableCharSequence(string));
	}

	public StringLiteral(Printable string) {
		super();
		this.string = string;
	}

	public void visit(SyntaxTreeVisitor syntaxTreeVisitor) throws EcmaSyntaxVisitingException {
		syntaxTreeVisitor.stringQuote();
		if (string != null) {
			syntaxTreeVisitor.identifier(string);
		}
		syntaxTreeVisitor.stringQuote();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof StringLiteral) {
			StringLiteral thatLiteral = (StringLiteral) obj;
			return string.equals(thatLiteral.string);
		}
		else if (obj instanceof CharSequence) {
			CharSequence thatCharSequence = (CharSequence) obj;
			return string.equals(thatCharSequence);
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return string.hashCode();
	}

}
